package com.sudo.service.res.task;

import com.sudo.common.annotation.Note;
import com.sudo.common.annotation.TaskComponent;
import com.sudo.common.utils.ProvinceCityUtil;
import com.sudo.service.annotation.VerifyTaskRequest;
import com.sudo.service.res.service.ResProvinceCityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author：DayDayUp
 * @Create：2023/2/9 18:32
 */
@Slf4j
@TaskComponent
public class ResourcesTaskModule {

    @Resource
    private ResProvinceCityService resProvinceCityService;

    @VerifyTaskRequest
    @Note(desc = "爬取全国省市区数据",params = "url(String,true,https://baidu.com,统计局网址)")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void crawlResProvinceCity(Map<String,Object> paramMap) {
        String url = paramMap.get("url").toString();
        List<ProvinceCityUtil.SysCity> cityList = ProvinceCityUtil.getProvinces(url);
        resProvinceCityService.refreshData(cityList);
    }
}
